<?php
declare(strict_types=1);

use SixShop\Message\Controller\Admin\{
    AnnouncementController,
    NotificationController,
    PrivateMessageController,
    MessageTemplateController,
    MessageSettingController,
    MessageController,
};
use SixShop\System\Middleware\MacroPageMiddleware;
use think\facade\Route;

// 后台管理API路由
// 路由前缀: /admin/message

// 公告管理路由
Route::resource('announcement', AnnouncementController::class, function () {
    Route::get('/', [AnnouncementController::class, 'getList']); // 覆盖默认的index路由
    Route::get('detail', [AnnouncementController::class, 'getDetail']);
    //Route::post('add', [AnnouncementController::class, 'add']);
   /* Route::post('update', [AnnouncementController::class, 'update']);
    Route::post('delete', [AnnouncementController::class, 'delete']);*/
    Route::post('batch_delete', [AnnouncementController::class, 'batchDelete']);
    Route::post('update_status', [AnnouncementController::class, 'updateStatus']);
})->middleware(['auth']);

// 通知管理路由
Route::resource('notification', NotificationController::class, function () {
    Route::get('/', [NotificationController::class, 'getList']); // 覆盖默认的index路由
    Route::get('detail', [NotificationController::class, 'getDetail']);
    Route::post('send_to_user', [NotificationController::class, 'sendToUser']);
    Route::post('send_to_users', [NotificationController::class, 'sendToUsers']);
    Route::post('send_global', [NotificationController::class, 'sendGlobal']);
    Route::post('delete', [NotificationController::class, 'delete']);
    Route::post('batch_delete', [NotificationController::class, 'batchDelete']);
})->middleware(['auth']);

// 私信管理路由
Route::resource('private_message', PrivateMessageController::class, function () {
    Route::get('/', [PrivateMessageController::class, 'getList']); // 覆盖默认的index路由
    Route::get('detail', [PrivateMessageController::class, 'getDetail']);
    Route::post('send_system_message', [PrivateMessageController::class, 'sendSystemMessage']);
    Route::post('batch_send_system_message', [PrivateMessageController::class, 'batchSendSystemMessage']);
    Route::post('delete', [PrivateMessageController::class, 'delete']);
    Route::post('batch_delete', [PrivateMessageController::class, 'batchDelete']);
})->middleware(['auth']);

// 消息模板管理路由
Route::resource('template', MessageTemplateController::class, function () {
    Route::get('detail', [MessageTemplateController::class, 'getDetail']);
    //Route::put('add_template', [MessageTemplateController::class, 'save']);
    Route::post('batch_delete', [MessageTemplateController::class, 'batchDelete']);
    Route::post('update_status', [MessageTemplateController::class, 'updateStatus']);
})->middleware(['auth']);

// 消息设置管理路由
Route::group('setting', function () {
    // 获取消息设置列表
    Route::get('list', [MessageSettingController::class, 'getList']);
    // 获取系统默认设置
    Route::get('default', [MessageSettingController::class, 'getDefaultSetting']);
    // 获取用户消息设置
    Route::get('user', [MessageSettingController::class, 'getUserSetting']);
    // 更新系统默认设置
    Route::post('update_default', [MessageSettingController::class, 'updateDefaultSetting']);
    // 更新用户消息设置
    Route::post('update_user', [MessageSettingController::class, 'updateUserSetting']);
})->middleware(['auth']);

// 获取消息列表
Route::resource('', MessageController::class)
    ->only(['index', 'read'])
    ->middleware(['auth', MacroPageMiddleware::class]);
